package org.apache.struts2.plugin.json.writer;

import java.io.OutputStream;
import org.apache.struts2.plugin.json.model.JSONArray;
import org.apache.struts2.plugin.json.model.JSONBoolean;
import org.apache.struts2.plugin.json.model.JSONNumber;
import org.apache.struts2.plugin.json.model.JSONObject;
import org.apache.struts2.plugin.json.model.JSONString;
import org.apache.struts2.plugin.json.model.JSONValue;
import org.apache.struts2.plugin.json.model.JSONValue;
import org.apache.struts2.plugin.json.model.JSONValue;

/**
 * @author VERDOÏA Laurent <verdoialaurent@gmail.com>
 */
public abstract class JSONWriterFactory {

    public static AbstractJSONWriter create(JSONValue content,
            OutputStream out) {
        if (content instanceof JSONArray) {
            return new JSONArrayWriter((JSONArray) content, out);
        } else if (content instanceof JSONBoolean) {
            return new JSONBooleanWriter((JSONBoolean) content, out);
        } else if (content instanceof JSONNumber) {
            return new JSONNumberWriter((JSONNumber) content, out);
        } else if (content instanceof JSONObject) {
            return new JSONObjectWriter((JSONObject) content, out);
        } else {
            return new JSONStringWriter((JSONString) content, out);
        }
    }
}
